home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / rl / build-bin / padd < prev    next >
Encoding:
Text File  |  2002-06-04  |  3.0 KB  |  134 lines

  1. #!/bin/sh
  2. # padd - package add script
  3. # copyright (c) 2000, joseph cheek, joseph@redmondlinux.org
  4. # released under gpl.
  5. # $1: pathname of package to add
  6. # ex: padd /usr/src/RedmondLinux/SRPMS/mypackage-1.1-1.src.rpm
  7. # ex: padd mypackage-1.1-1.src.rpm
  8. # opts: -q: quiet [don't print status messages]
  9. #       -v: verbose
  10. #    -l: language to add to [default: all languages]
  11.  
  12. # BUG: use getopts instead
  13. LANG=
  14. ERROR=0
  15.  
  16. if [ "n$1" = "n-q" ]; then # -q
  17.   QUIET="-q"
  18.   shift
  19. fi
  20.  
  21. if [ "n$1" = "n-v" ]; then # -v
  22.   VERBOSE="-v"
  23.   shift
  24. fi
  25.  
  26. if [ "n$1" = "n-l" ]; then # -l
  27.   LANG="$2"
  28.   shift
  29.   shift
  30. fi
  31.  
  32.  
  33. # constants and vars
  34.  
  35. RL_ROOT=/opt/redmondlinux
  36. BUILD_NUM_FILE=$RL_ROOT/builds/CURRENT_BUILD
  37. BUILD_NUM=`cat $BUILD_NUM_FILE`
  38.  
  39. BUILD_ROOT=$RL_ROOT/builds/$BUILD_NUM
  40.  
  41. cd $BUILD_ROOT
  42. LANG_TO_PROCESS=`echo ${LANG}*`
  43. cd -
  44. [ $VERBOSE ] && echo Languages to process: $LANG_TO_PROCESS
  45.  
  46. while [ $# -ge 1 ]; do # for each file to add
  47.  
  48.   if [ ! -r "$1" ]; then # file doesn't exist
  49.     echo `basename $0`: can\'t find \"$1\" >&2
  50.     shift ; continue
  51.   fi
  52.  
  53.   for lang in $LANG_TO_PROCESS; do # for each lang
  54.     [ $VERBOSE ] && echo checking $lang
  55.  
  56.     PAT_FILE=$BUILD_ROOT/$lang/rl/data/regex_patterns.txt
  57.  
  58. # find pattern to match
  59.  
  60.     { while read LINE; do
  61.  
  62.       if [ "`echo $LINE | cut -c 1`" = "#" ] || [ "$LINE" = "" ]; then
  63. # comment or blank line, continue
  64.         continue
  65.       fi
  66.  
  67. # separate the regexp and the directory
  68.       REGEX=`echo $LINE | cut -f 1 -d \ `
  69.       DIR=`echo $LINE | cut -f 2 -d \ `
  70.       [ $VERBOSE ] && echo $REGEX = $DIR
  71.  
  72. # test for match
  73.       basename "$1" | grep -q -e $REGEX
  74.       MATCH=$[ ! $? ]
  75.       [ $VERBOSE ] && echo match = $MATCH
  76.  
  77.       [ $MATCH -eq 1 ] && break
  78.  
  79.     done } < $PAT_FILE # find pattern to match
  80.  
  81. # match?
  82.     if [ $MATCH -eq 1 ]; then
  83. # yes, perform update
  84.       [ $VERBOSE ] && echo fadd $QUIET -l $lang "$1" $DIR
  85. # we can specify a file is not to be added by making DIR=/dev/null
  86.       [ "$DIR" = "/dev/null" ] && echo /dev/null && shift && continue 2
  87.       fadd $QUIET -l $lang "$1" $DIR
  88.  
  89. # successful?
  90.       RETURN=$?
  91. # no, continue
  92.       [ $RETURN -gt 0 ] && continue
  93. # yes, update pkgs.db
  94.  
  95.       BASENAME=`basename "$1"`
  96.       UPDATED_FILE="$BUILD_ROOT/$lang/$DIR/$BASENAME"
  97.  
  98. # source rpm?
  99.  
  100.       if [ "$BASENAME" = `basename "$1" .src.rpm`.src.rpm ]; then
  101.     echo source rpm, not updating && continue
  102.       fi
  103.  
  104. # get needed info
  105.  
  106.       PACK_SIZE=`ls -l $UPDATED_FILE | tr -s \  | cut -d \  -f 5`  # packed size
  107.       eval `rpmextr --shell $UPDATED_FILE` # unpacked size, package name, version, release
  108.       PKGS_DB=$BUILD_ROOT/$lang/rl/data/pkgs.db
  109.       DB_LINE=`grep \[A-Z\]*:$PKG_NAME:.* < $PKGS_DB` # get line from DB
  110.  
  111. # no line?  exit
  112.       [ "$DB_LINE" = "" ] && continue
  113.  
  114.       perl -pi -e \
  115.   "s/:$PKG_NAME:(.*?:.*?):.*?:(.*?):.*?:.*::/:$PKG_NAME:\$1:$PKG_SIZE:\$2:$PACK_SIZE:$PKG_VERS-$PKG_RELEASE::/g" $PKGS_DB
  116.  
  117.       DB_LINE=`grep \[A-Z\]*:$PKG_NAME:.* < $PKGS_DB`
  118.       echo $DB_LINE
  119.       continue
  120.  
  121.     fi
  122.  
  123.     [ $QUIET ] || echo match not found.  no add performed.
  124.  
  125.   done # for each lang
  126.  
  127.   shift
  128.  
  129. done # for each file to add
  130.